package main.java.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo10 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入需要修改的ID");
        int id = sc.nextInt();
        System.out.println("请输入修改后的密码");
        String pwd = sc.next();
        System.out.println("请输入修改后的昵称");
        String nickname = sc.next();
        System.out.println("请输入修改后的年龄");
        int age = sc.nextInt();
        try(Connection connection = DBUtil.getConnection()){
            String sql = "UPDATE userinfo SET password=?,nickname=?,age=? WHERE ID = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,pwd);
            ps.setString(2,nickname);
            ps.setInt(3,age);
            ps.setInt(4,id);
            int num = ps.executeUpdate();
            System.out.println(num>0?"修改成功！":"修改失败！");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
